Stored Procedures [dbo].[dt_checkinobject]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@chObjectTypechar(4)4
@vchObjectNamevarchar(255)255
@vchCommentvarchar(255)255
@vchLoginNamevarchar(255)255
@vchPasswordvarchar(255)255
@iVCSFlagsint4
@iActionFlagint4
@txStream1text16
@txStream2text16
@txStream3text16
Permissions
TypeActionOwning Principal
GrantExecutepublic
SQL Script
create proc dbo.dt_checkinobject
    @chObjectType  char(4),
    @vchObjectName varchar(255),
    @vchComment    varchar(255)='',
    @vchLoginName  varchar(255),
    @vchPassword   varchar(255)='',
    @iVCSFlags     int = 0,
    @iActionFlag   int = 0,   /* 0 => AddFile, 1 => CheckIn */
    @txStream1     Text = '', /* drop stream   */ /* There is a bug that if items are NULL they do not pass to OLE servers */
    @txStream2     Text = '', /* create stream */
    @txStream3     Text = ''  /* grant stream  */


as

    set nocount on

    declare @iReturn int
    declare @iObjectId int
    select @iObjectId = 0
    declare @iStreamObjectId int

    declare @VSSGUID varchar(100)
    select @VSSGUID = 'SQLVersionControl.VCS_SQL'

    declare @iPropertyObjectId int
    select @iPropertyObjectId  = 0

    select @iPropertyObjectId = (select objectid from dbo.dtproperties where property = 'VCSProjectID')

    declare @vchProjectName   varchar(255)
    declare @vchSourceSafeINI varchar(255)
    declare @vchServerName    varchar(255)
    declare @vchDatabaseName  varchar(255)
    declare @iReturnValue      int
    declare @pos              int
    declare @vchProcLinePiece varchar(255)

    
    exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSProject',       @vchProjectName   OUT
    exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSourceSafeINI', @vchSourceSafeINI OUT
    exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSQLServer',     @vchServerName    OUT
    exec dbo.dt_getpropertiesbyid_vcs @iPropertyObjectId, 'VCSSQLDatabase',   @vchDatabaseName  OUT

    if @chObjectType = 'PROC'
    begin
        if @iActionFlag = 1
        begin
            /* Procedure Can have up to three streams
            Drop Stream, Create Stream, GRANT stream */


            begin tran compile_all

            /* try to compile the streams */
            exec (@txStream1)
            if @@error <> 0 GOTO E_Compile_Fail

            exec (@txStream2)
            if @@error <> 0 GOTO E_Compile_Fail

            exec (@txStream3)
            if @@error <> 0 GOTO E_Compile_Fail
        end

        exec @iReturn = master.dbo.sp_OACreate @VSSGUID, @iObjectId OUT
        if @iReturn <> 0 GOTO E_OAError

        exec @iReturn = master.dbo.sp_OAGetProperty @iObjectId, 'GetStreamObject', @iStreamObjectId OUT
        if @iReturn <> 0 GOTO E_OAError
        
        if @iActionFlag = 1
        begin
            
            declare @iStreamLength int
            
            select @pos=1
            select @iStreamLength = datalength(@txStream2)
            
            if @iStreamLength > 0
            begin
            
                while @pos < @iStreamLength
                begin
                        
                    select @vchProcLinePiece = substring(@txStream2, @pos, 255)
                    
                    exec @iReturn = master.dbo.sp_OAMethod @iStreamObjectId, 'AddStream', @iReturnValue OUT, @vchProcLinePiece
                    if @iReturn <> 0 GOTO E_OAError
                    
                    select @pos = @pos + 255
                    
                end
            
                exec @iReturn = master.dbo.sp_OAMethod @iObjectId,
                                                        'CheckIn_StoredProcedure',
                                                        NULL,
                                                        @sProjectName = @vchProjectName,
                                                        @sSourceSafeINI = @vchSourceSafeINI,
                                                        @sServerName = @vchServerName,
                                                        @sDatabaseName = @vchDatabaseName,
                                                        @sObjectName = @vchObjectName,
                                                        @sComment = @vchComment,
                                                        @sLoginName = @vchLoginName,
                                                        @sPassword = @vchPassword,
                                                        @iVCSFlags = @iVCSFlags,
                                                        @iActionFlag = @iActionFlag,
                                                        @sStream = ''
                                        
            end
        end
        else
        begin
        
            select colid, text into #ProcLines
            from syscomments
            where id = object_id(@vchObjectName)
            order by colid

            declare @iCurProcLine int
            declare @iProcLines int
            select @iCurProcLine = 1
            select @iProcLines = (select count(*) from #ProcLines)
            while @iCurProcLine <= @iProcLines
            begin
                select @pos = 1
                declare @iCurLineSize int
                select @iCurLineSize = len((select text from #ProcLines where colid = @iCurProcLine))
                while @pos <= @iCurLineSize
                begin                
                    select @vchProcLinePiece = convert(varchar(255),
                        substring((select text from #ProcLines where colid = @iCurProcLine),
                                  @pos, 255 ))
                    exec @iReturn = master.dbo.sp_OAMethod @iStreamObjectId, 'AddStream', @iReturnValue OUT, @vchProcLinePiece
                    if @iReturn <> 0 GOTO E_OAError
                    select @pos = @pos + 255                  
                end
                select @iCurProcLine = @iCurProcLine + 1
            end
            drop table #ProcLines

            exec @iReturn = master.dbo.sp_OAMethod @iObjectId,
                                                    'CheckIn_StoredProcedure',
                                                    NULL,
                                                    @sProjectName = @vchProjectName,
                                                    @sSourceSafeINI = @vchSourceSafeINI,
                                                    @sServerName = @vchServerName,
                                                    @sDatabaseName = @vchDatabaseName,
                                                    @sObjectName = @vchObjectName,
                                                    @sComment = @vchComment,
                                                    @sLoginName = @vchLoginName,
                                                    @sPassword = @vchPassword,
                                                    @iVCSFlags = @iVCSFlags,
                                                    @iActionFlag = @iActionFlag,
                                                    @sStream = ''
        end

        if @iReturn <> 0 GOTO E_OAError

        if @iActionFlag = 1
        begin
            commit tran compile_all
            if @@error <> 0 GOTO E_Compile_Fail
        end

    end

CleanUp:
    return

E_Compile_Fail:
    declare @lerror int
    select @lerror = @@error
    rollback tran compile_all
    RAISERROR (@lerror,16,-1)
    goto CleanUp

E_OAError:
    if @iActionFlag = 1 rollback tran compile_all
    exec dbo.dt_displayoaerror @iObjectId, @iReturn
    goto CleanUp
GO
GRANT EXECUTE ON  [dbo].[dt_checkinobject] TO [public]
GO
Uses
Used By